package com.mvc4g.example.client.action;

import com.mvc4g.client.ActionInterface;
import com.mvc4g.client.Controller;
import com.mvc4g.example.client.Constants;
import com.mvc4g.example.client.bean.UserBean;
import com.mvc4g.example.client.view.MainView;
import com.mvc4g.example.client.view.user.DisplayUserView;

public class CreateUserAction implements ActionInterface, Constants {

	@Override
	public void execute(Controller controller, Object form) {
		UserBean user = (UserBean) form;
		String lastName = user.getLastName();
		if((lastName == null) || (lastName.length() == 0)){
			((MainView) controller.getView(MAIN_VIEW)).displayMessage("Missing last name");
		}
		else {
			MainView mainView = (MainView)controller.getView(MAIN_VIEW);
			DisplayUserView displayView = (DisplayUserView)controller.getView(DISPLAY_VIEW);
			mainView.displayMessage("User Creation succeeded");
			mainView.changePage(displayView);
			displayView.init(user);
		}

	}

}
